const ImageProcessor = require('../../utils/imageProcessor');

Component({
  properties: {
    imagePath: {
      type: String,
      value: ''
    },
    index: {
      type: Number,
      value: 0
    },
    isActive: {
      type: Boolean,
      value: false
    }
  },
  
  data: {
    processed: false,
    processingFailed: false
  },
  
  observers: {
    'imagePath': function(newPath) {
      if (newPath) {
        this.processImage(newPath);
      }
    }
  },
  
  methods: {
    // 处理图像
    processImage: function(imagePath) {
      this.setData({
        processed: false,
        processingFailed: false
      });
      
      ImageProcessor.enhanceDocument(imagePath)
        .then(() => {
          this.setData({
            processed: true
          });
        })
        .catch(err => {
          console.error('图像处理失败:', err);
          this.setData({
            processingFailed: true
          });
        });
    },
    
    // 点击文档
    onTap: function() {
      this.triggerEvent('tap', {
        index: this.data.index,
        imagePath: this.data.imagePath
      });
    },
    
    // 长按文档
    onLongPress: function() {
      this.triggerEvent('longpress', {
        index: this.data.index,
        imagePath: this.data.imagePath
      });
    }
  }
})